package com.ruoyi.common.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * JWT配置类
 * 
 * @author ruoyi
 */
@Component
@ConfigurationProperties(prefix = "jwt")
public class JwtConfig
{
    /**
     * JWT密钥 - 使用足够长度的密钥支持HS512算法
     */
    private String secret = "ruoyi-jwt-secret-key-for-token-generation-and-validation-with-sufficient-length-to-support-hs512-algorithm-requirements";

    /**
     * 访问Token过期时间（分钟）
     */
    private Long accessTokenExpire = 120L;

    /**
     * 刷新Token过期时间（天）
     */
    private Long refreshTokenExpire = 7L;

    /**
     * Token请求头名称
     */
    private String tokenHeader = "Authorization";

    /**
     * Token前缀
     */
    private String tokenPrefix = "Bearer ";

    /**
     * 是否启用JWT认证
     */
    private Boolean enabled = true;

    /**
     * JWT认证路径前缀
     */
    private String pathPrefix = "/api";

    /**
     * 排除路径（不需要JWT认证的路径）
     */
    private String[] excludePaths = {
        "/api/auth/login",
        "/api/auth/refresh",
        "/api/auth/logout",
        "/test/**",
        "/swagger-ui/**",
        "/swagger-resources/**",
        "/v3/api-docs/**",
        "/webjars/**",
        "/druid/**"
    };

    public String getSecret()
    {
        return secret;
    }

    public void setSecret(String secret)
    {
        this.secret = secret;
    }

    public Long getAccessTokenExpire()
    {
        return accessTokenExpire;
    }

    public void setAccessTokenExpire(Long accessTokenExpire)
    {
        this.accessTokenExpire = accessTokenExpire;
    }

    public Long getRefreshTokenExpire()
    {
        return refreshTokenExpire;
    }

    public void setRefreshTokenExpire(Long refreshTokenExpire)
    {
        this.refreshTokenExpire = refreshTokenExpire;
    }

    public String getTokenHeader()
    {
        return tokenHeader;
    }

    public void setTokenHeader(String tokenHeader)
    {
        this.tokenHeader = tokenHeader;
    }

    public String getTokenPrefix()
    {
        return tokenPrefix;
    }

    public void setTokenPrefix(String tokenPrefix)
    {
        this.tokenPrefix = tokenPrefix;
    }

    public Boolean getEnabled()
    {
        return enabled;
    }

    public void setEnabled(Boolean enabled)
    {
        this.enabled = enabled;
    }

    public String getPathPrefix()
    {
        return pathPrefix;
    }

    public void setPathPrefix(String pathPrefix)
    {
        this.pathPrefix = pathPrefix;
    }

    public String[] getExcludePaths()
    {
        return excludePaths;
    }

    public void setExcludePaths(String[] excludePaths)
    {
        this.excludePaths = excludePaths;
    }

    /**
     * 获取访问Token过期时间（毫秒）
     * 
     * @return 过期时间毫秒数
     */
    public Long getAccessTokenExpireMillis()
    {
        return accessTokenExpire * 60 * 1000L;
    }

    /**
     * 获取刷新Token过期时间（毫秒）
     * 
     * @return 过期时间毫秒数
     */
    public Long getRefreshTokenExpireMillis()
    {
        return refreshTokenExpire * 24 * 60 * 60 * 1000L;
    }
}